{
  "cells": [
    {
      "cell_type": "markdown",
      "id": "fbba28bc-1f60-41fb-81dc-1b58cda63649",
      "metadata": {
        "id": "fbba28bc-1f60-41fb-81dc-1b58cda63649"
      },
      "source": [
        "<div>\n",
        "    <h1 >Large Language Models Projects</h1>\n",
        "    <h3>Apply and Implement Strategies for Large Language Models</h3>\n",
        "    <h2>2_3-ChromaDB Client</h2>\n",
        "</div>\n",
        "\n",
        "by [Pere Martra](https://www.linkedin.com/in/pere-martra/)\n",
        "\n",
        "This notebook accesses the Chroma server that has been previously created with the notebook 2_2-ChromaDB Server mode.\n",
        "_________"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "id": "599371fc-8b8b-468a-9347-b393f68ae88a",
      "metadata": {
        "id": "599371fc-8b8b-468a-9347-b393f68ae88a"
      },
      "outputs": [],
      "source": [
        "import chromadb"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "id": "c9b47aca-86b3-4978-8adb-e0e0152423ef",
      "metadata": {
        "id": "c9b47aca-86b3-4978-8adb-e0e0152423ef"
      },
      "outputs": [],
      "source": [
        "client = chromadb.HttpClient(host='localhost', port=8000)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "id": "99e6316b-1fff-4aa7-a393-10da2f58707e",
      "metadata": {
        "id": "99e6316b-1fff-4aa7-a393-10da2f58707e"
      },
      "outputs": [],
      "source": [
        "collection_local = client.get_collection(name=\"local_news_collection\")\n",
        "results = collection_local.query(query_texts=[\"laptop\"], n_results=10 )"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "id": "3432d427-2236-4300-bad7-676b60245830",
      "metadata": {
        "id": "3432d427-2236-4300-bad7-676b60245830",
        "outputId": "1e584ad1-2bce-4045-dc05-12e85669c1d9"
      },
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "{'ids': [['id173', 'id829', 'id117', 'id535', 'id141', 'id218', 'id390', 'id273', 'id56', 'id900']], 'distances': [[0.8593592047691345, 1.0294400453567505, 1.0793328285217285, 1.093001365661621, 1.1329681873321533, 1.2130439281463623, 1.2143322229385376, 1.2164145708084106, 1.222063660621643, 1.275417447090149]], 'embeddings': None, 'metadatas': [[{'topic': 'TECHNOLOGY'}, {'topic': 'TECHNOLOGY'}, {'topic': 'TECHNOLOGY'}, {'topic': 'TECHNOLOGY'}, {'topic': 'TECHNOLOGY'}, {'topic': 'TECHNOLOGY'}, {'topic': 'TECHNOLOGY'}, {'topic': 'TECHNOLOGY'}, {'topic': 'TECHNOLOGY'}, {'topic': 'TECHNOLOGY'}]], 'documents': [['The Legendary Toshiba is Officially Done With Making Laptops', '3 gaming laptop deals you can’t afford to miss today', 'Lenovo and HP control half of the global laptop market', 'Asus ROG Zephyrus G14 gaming laptop announced in India', 'Acer Swift 3 featuring a 10th-generation Intel Ice Lake CPU, 2K screen, and more launched in India for INR 64999 (US$865)', \"Apple's Next MacBook Could Be the Cheapest in Company's History\", \"Features of Huawei's Desktop Computer Revealed\", 'Redmi to launch its first gaming laptop on August 14: Here are all the details', 'Toshiba shuts the lid on laptops after 35 years', 'This is the cheapest Windows PC by a mile and it even has a spare SSD slot']], 'uris': None, 'data': None}\n"
          ]
        }
      ],
      "source": [
        "print (results)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "id": "91653be5-7c1e-4f9f-84ed-d76ec573f465",
      "metadata": {
        "id": "91653be5-7c1e-4f9f-84ed-d76ec573f465"
      },
      "outputs": [],
      "source": []
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3 (ipykernel)",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.10.12"
    },
    "colab": {
      "provenance": []
    }
  },
  "nbformat": 4,
  "nbformat_minor": 5
}